//
//  HWReChargeViewController.m
//  嗨文
//
//  Created by 响当当 on 2019/1/14.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWReChargeViewController.h"
#import "HWRechargeView.h"

@interface HWReChargeViewController ()
@property (nonatomic, strong)HWRechargeView *hwRechargeView;
@end

@implementation HWReChargeViewController

- (HWRechargeView *)hwRechargeView
{
    if (!_hwRechargeView)
    {
        _hwRechargeView = [[HWRechargeView alloc] initWithFrame:CGRectMake(0,NAVIBAR_HEIGHT,SCREEN_WIDTH,SCREEN_HEIGHT-NAVIBAR_HEIGHT-TABBAR_HEIGHT)];
        WeakSelf(self)
        _hwRechargeView.paySuccessBlock = ^{
            [weakSelf getInfor];
        };
        
    }
    return _hwRechargeView;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setTitle:@"充值"];
    [self setDefaultNav];
    
    [self hidePay];
    [self getInfor];
    [self buryPoint];
    
    [self.view addSubview:self.hwRechargeView];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
   
}

#pragma mark - 获取充值信息数据
- (void)getInfor
{
    
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token                               };
    
    WeakSelf(self)
    [MyInfoManager getBookCoin:prarmers sucess:^(id  _Nonnull acceptData) {
        DISMISS_SVP(1.0f);
        HWRechargeModel *model = [[HWRechargeModel alloc]initWithDic:acceptData];
        [weakSelf.hwRechargeView getInfo:model];
    } fail:^(NSError * _Nullable error) {
     
    }];
}

- (void)buryPoint
{
    NSString *lastStayTime = [kUserDefaults objectForKey:@"time"];
    NSString *nowStayTime = [NSString stringWithFormat:@"%ld",[[HWUtilties getNowTimeTimestamp3] integerValue] - lastStayTime.integerValue];
    
    [HWUtilties buryPointWithStayTime:nowStayTime
                            timestamp:[HWUtilties getNowTimeTimestamp3]
                             memberId:current_User.userID
                              fromUrl:nil
                                toUrl:@"/rechargeCoin"
                               fromId:nil
                                 toId:@"41f35ad5b8f4552d"];
}

- (void)hidePay
{
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token                               };
    
    WeakSelf(self)
    [MyInfoManager hidePay:prarmers sucess:^(id  _Nonnull acceptData) {
        DISMISS_SVP(1.0f);
        [weakSelf.hwRechargeView hideWexiOrAliPay:[acceptData stringValue]];
    } fail:^(NSError * _Nullable error) {
        
    }];
}
@end
